package demo.controller;

import demo.db.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping
public class AuthController {

    @GetMapping("/auth")
    public @ResponseBody String view(HttpServletRequest request) {
        User user = (User) request.getAttribute("user");
        if (user.getUsername() != null) {
            return user.getUsername() + " login success";
        } else {
            return "login fail";
        }
    }
}
